﻿using System; 
using System.Collections.Generic;
using System.Text;
using XXX.Models;
using fuzhu;
using System.Data; 
using XXX.Models.XXXEntities;
using LH.U8API.Bus;
using ADODB;
using XXX.Common;
using System.Data.SqlClient;

namespace XXX.Bo
{
   public static class SRMService
    {
        public static readonly string conStrSRM = Common.AppSettings.GetAppSeting("srmDB");



        /// <summary>
        /// 查询未到货的送货单
        /// </summary>
        /// <param name="iid"></param>
        /// <returns></returns>
        public static RetModel GetSongHuo(string ccode)
        {
            try
            {
                string sql = string.Format(@" SELECT BillNo,BillDate,VenCode,VenName,cInvCode,cInvName,cInvStd,cComUnitName,cPoid,iPosid,Num,
cast(autoid as varchar(20)) as songhuoid FROM zdy_v_getsonghuo
WHERE  1=1");
                if (ccode != "0")
                {
                    sql += string.Format(" and BillNo = '{0}'", ccode);
                }
                DataTable dt = DbHelper2.Execute(sql,  conStrSRM).Tables[0];
                
            
                    List<SrmSongHuo> u8wms001s1 = TableListConverter<SrmSongHuo>.TableToList2(dt);
                    List<object> u8wms002s = u8wms001s1.ConvertAll(s => (object)s);
                    return DBService.ReOK(u8wms002s);
              

            }
            catch (Exception ex)
            {
                return DBService.ReError(ex.Message);
            }

        }



        /// <summary>
        /// 查询未到货的送货单
        /// </summary>
        /// <param name="iid"></param>
        /// <returns></returns>
        public static RetModel GetSongHuoBarcode(string ccode)
        {
            try
            {
                //也是视图
                string sql = string.Format(@"select cinvcode,barcodeno,ichecked from  zdy_v_getsonghuobarcode
WHERE  1=1  and BillNo = '{0}'", ccode);
               
                DataTable dt = DbHelper2.Execute(sql, conStrSRM).Tables[0];

                //根据autid进行查询，并汇总  


                List<SongHuoBarcodes> u8wms001s1 = TableListConverter<SongHuoBarcodes>.TableToList2(dt);
                List<object> u8wms002s = u8wms001s1.ConvertAll(s => (object)s);
                return DBService.ReOK(u8wms002s);
                 

            }
            catch (Exception ex)
            {
                return DBService.ReError(ex.Message);
            }

        }




    }
}
